package com.jd.sunny.java.reflect;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class TestReflect {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String className = "com.sunlin.reflect.Person";

        try {
            Class cla = Class.forName(className);
            Constructor[] constructor = cla.getConstructors();
            int constructorNumber = constructor.length;
            System.out.println(constructorNumber);

            Field[] fields = cla.getFields();
            for (int i = 0; i < fields.length; i++) {
                System.out.println(fields[i].getName());
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


//		try {
//			Class cla = Class.forName(className);
//			
//			
//			
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		}
        Reflection r = new Reflection();
        Person p = new Person(1, "����", "��");
        try {
            Object obj = r.getFiled(p, "name");
            String property = obj.toString();
            System.out.println(property);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

}
